import {actions} from '../base';
import helper from "../../helper";

let url = 'admin/api/app-source';

export default {
    namespaced: true,
    state: {
        all: helper.getCache('app-source.all', []),
        allName: helper.getCache('app-source.allName', {}),
        options: {
            status: [
                {label: '关闭', value: 0},
                {label: '正常', value: 1},
            ],
            type: {
                0: {label: '官方', value: 0, class: 'primary', },
                // 1: {label: '应用商店', value: 1, class: 'success', },
                // 2: {label: '分享渠道', value: 2, class: 'warning', },
                // 3: {label: '投放渠道', value: 3, class: 'danger', },
                4: {label: '试玩', value: 4, class: 'info', },
                5: {label: '抖音', value: 5, class: 'info', },
                6: {label: '快手', value: 6, class: 'info', },
                7: {label: 'Sigmob', value: 7, class: 'info', },
                8: {label: '荣耀', value: 8, class: 'info', },
                9: {label: '百度', value: 9, class: 'info', },
                10: {label: '腾讯', value: 10, class: 'info', },
                11: {label: 'UC', value: 11, class: 'info', },
            },
        },
        request: {
            all: false,
        }
    },
    mutations: {
        SET_ALL (state, data) {
            state.all = data;
            for (let i in data) {
                state.allName[data[i].id] = data[i].name;
            }
            helper.setCache('app-source.all', state.all)
            helper.setCache('app-source.allName', state.allName)
        },
        SET_REQUESTING (state, name) {
            state.request[name] = true;
        },
        SET_REQUESTED (state, name) {
            state.request[name] = false;
        }
    },
    actions: actions(url),
};
